package com.example.chenjun.myapplication.adapter;

import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.chenjun.myapplication.R;
import com.example.chenjun.myapplication.bean.CookBean;
import com.example.chenjun.myapplication.bean.LabelBean;

import java.util.List;

public class CookListAdapter extends BaseAdapter {
    private List<CookBean> mBeanList;

    @Override
    public int getCount() {
        return mBeanList == null ? 0 : mBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return mBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null){
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.app_list_item_cooks, parent, false);
        }
        TextView tvTitle = convertView.findViewById(R.id.tv_title);
        TextView tvContent = convertView.findViewById(R.id.tv_content);
        ImageView ivContent = convertView.findViewById(R.id.iv_content);
        CookBean cookBean = mBeanList.get(position);
        tvTitle.setText(cookBean.getTitle());
        tvContent.setText(cookBean.getImtro());
        Glide.with(parent.getContext())
                .asBitmap()
                .load(cookBean.getAlbums().get(0))
                .into(ivContent);
        return convertView;
    }

    public void setList(List<CookBean> list){
        mBeanList = list;
        notifyDataSetChanged();
    }
}
